<template>
  <div class="cart-control">
    <transition name="show">
      <div class="cart-cut iconfont"
           @click.stop="cutCart"
           v-show="food.count>0">&#xe653;</div>
    </transition>
    <div class="cart-count"
         v-show="food.count>0">
      {{food.count}}
    </div>
    <div class="cart-add iconfont"
         @click.stop="addCart">&#xe782;</div>
  </div>
</template>

<script>
  export default {
    name: "CartControl",
    props: {
      food: {
        type: Object,
        default(){
          return {}
        }
      }
    },
    methods: {
      addCart(e){
        // console.log(e);
        if(!this.food.count){
          this.$set(this.food, 'count', 1);
        }
        else this.food.count++;
        this.$emit('cartAdd', e.target);
      },
      cutCart(){
        if(this.food.count){
          this.food.count --;
        }
      }
    }

  }
</script>

<style scoped lang="stylus">
  // 设置过渡的持续时间以及过渡的表现形式
  .show-enter-active, .show-leave-active {
    transition: all 0.3s linear;
  }
    // 动画开始进入和动画离开
  .show-enter, .show-leave-to {
    opacity 0
    transform translate3d(24px,0,0)
  }
    //动画开始和动画开始离开
  .show-enter-to, .show-leave {
    opacity 1
    transform translate3d(0,0,0)
  }
.cart-control
  .cart-add, .cart-cut
    display inline-block
    padding 6px
    font-size 24px
    line-height 24px
    color rgb(0,160,220)
  .cart-count
    display inline-block
    vertical-align top
    width 12px
    padding-top 6px
    line-height 24px
    text-align center
    font-size 10px
    color rgb(147, 153,159)
</style>
